﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package reprise.ui.renderers {
    import flash.geom.*;
    import reprise.data.*;
    import reprise.utils.*;
    import reprise.css.propertyparsers.*;

    public class DefaultBorderRenderer extends AbstractCSSRenderer {

        protected static var SIDE_BOTTOM:int = 3;
        protected static var SIDE_RIGHT:int = 2;
        protected static var SIDE_TOP:int = 1;
        protected static var SIDE_LEFT:int = 4;

        protected function drawBorderInRect(_arg1:AdvancedColor, _arg2:String, _arg3:Number, _arg4:Point, _arg5:Point, _arg6:Point, _arg7:Point, _arg8:int):void{
            var _local11:Number;
            var _local9:int;
            var _local10:Number = 1;
            if (_arg1){
                _local9 = _arg1.rgb();
                _local10 = _arg1.opacity();
            };
            switch (_arg2){
                case Border.BORDER_STYLE_DOTTED:
                case Border.BORDER_STYLE_DASHED:
                    _local11 = _arg3;
                    if (_arg2 == Border.BORDER_STYLE_DASHED){
                        _local11 = (_local11 * 3);
                    };
                    m_display.graphics.lineStyle(_arg3, _local9, _local10, false, "normal", "none");
                    switch (_arg8){
                        case SIDE_TOP:
                            _arg4.y = (_arg4.y + (_arg3 / 2));
                            _arg5.y = (_arg5.y + (_arg3 / 2));
                            break;
                        case SIDE_RIGHT:
                            _arg4.x = (_arg4.x - (_arg3 / 2));
                            _arg5.x = (_arg5.x - (_arg3 / 2));
                            break;
                        case SIDE_BOTTOM:
                            _arg4.y = (_arg4.y - (_arg3 / 2));
                            _arg5.y = (_arg5.y - (_arg3 / 2));
                            break;
                        case SIDE_LEFT:
                            _arg4.x = (_arg4.x + (_arg3 / 2));
                            _arg5.x = (_arg5.x + (_arg3 / 2));
                            break;
                    };
                    GfxUtil.drawDashedLine(m_display, _arg4.x, _arg4.y, _arg5.x, _arg5.y, _local11, _local11);
                    break;
                case Border.BORDER_STYLE_SOLID:
                    m_display.graphics.lineStyle();
                    m_display.graphics.beginFill(_local9, _local10);
                    m_display.graphics.moveTo(_arg4.x, _arg4.y);
                    m_display.graphics.lineTo(_arg5.x, _arg5.y);
                    m_display.graphics.lineTo(_arg6.x, _arg6.y);
                    m_display.graphics.lineTo(_arg7.x, _arg7.y);
                    m_display.graphics.moveTo(_arg4.x, _arg4.y);
                    m_display.graphics.endFill();
                    break;
            };
        }
        override public function draw():void{
            var _local7:int;
            var _local8:Number;
            var _local13:AdvancedColor;
            var _local14:Number;
            m_display.graphics.clear();
            var _local1:Object = {top:m_styles.borderTopWidth, right:m_styles.borderRightWidth, bottom:m_styles.borderBottomWidth, left:m_styles.borderLeftWidth};
            var _local2:Object = {top:m_styles.borderTopStyle, right:m_styles.borderRightStyle, bottom:m_styles.borderBottomStyle, left:m_styles.borderLeftStyle};
            var _local3:Object = {top:m_styles.borderTopColor, right:m_styles.borderRightColor, bottom:m_styles.borderBottomColor, left:m_styles.borderLeftColor};
            var _local4:Array = [];
            var _local5:Boolean;
            var _local6:Array = ["borderTopLeftRadius", "borderTopRightRadius", "borderBottomRightRadius", "borderBottomLeftRadius"];
            _local7 = 0;
            while (_local7 < _local6.length) {
                _local8 = m_styles[_local6[_local7]];
                if ((m_styles[_local6[_local7]] is Number)){
                    _local8 = m_styles[_local6[_local7]];
                } else {
                    _local8 = 0;
                };
                if (_local8 != 0){
                    _local5 = true;
                };
                _local4.push(_local8);
                _local7++;
            };
            if (((((_local5) && (_local1.top))) && ((_local2.top == "solid")))){
                _local13 = ((_local3.top) || (new AdvancedColor(0)));
                _local14 = _local1.top;
                m_display.graphics.lineStyle(_local14, _local13.rgb(), _local13.opacity(), true, "normal", "square", "miter", 2);
                GfxUtil.drawRoundRect(m_display, (_local14 / 2), (_local14 / 2), (m_width - _local14), (m_height - _local14), _local4);
                return;
            };
            var _local9:Point = new Point();
            var _local10:Point = new Point();
            var _local11:Point = new Point();
            var _local12:Point = new Point();
            if ((((((_local1.top > 0)) && (!((_local2.top == "none"))))) && (_local3.top))){
                _local9.x = 0;
                _local9.y = 0;
                _local10.x = m_width;
                _local10.y = 0;
                _local11.x = (m_width - _local1.right);
                _local11.y = _local1.top;
                _local12.x = _local1.left;
                _local12.y = _local1.top;
                drawBorderInRect(_local3.top, _local2.top, _local1.top, _local9, _local10, _local11, _local12, SIDE_TOP);
            };
            if ((((((_local1.right > 0)) && (!((_local2.right == "none"))))) && (_local3.right))){
                _local9.x = m_width;
                _local9.y = 0;
                _local10.x = m_width;
                _local10.y = m_height;
                _local11.x = (m_width - _local1.right);
                _local11.y = (m_height - _local1.bottom);
                _local12.x = (m_width - _local1.right);
                _local12.y = _local1.top;
                drawBorderInRect(_local3.right, _local2.right, _local1.right, _local9, _local10, _local11, _local12, SIDE_RIGHT);
            };
            if ((((((_local1.bottom > 0)) && (!((_local2.bottom == "none"))))) && (_local3.bottom))){
                _local9.x = 0;
                _local9.y = m_height;
                _local10.x = m_width;
                _local10.y = m_height;
                _local11.x = (m_width - _local1.right);
                _local11.y = (m_height - _local1.bottom);
                _local12.x = _local1.left;
                _local12.y = (m_height - _local1.bottom);
                drawBorderInRect(_local3.bottom, _local2.bottom, _local1.bottom, _local9, _local10, _local11, _local12, SIDE_BOTTOM);
            };
            if ((((((_local1.left > 0)) && (!((_local2.left == "none"))))) && (_local3.left))){
                _local9.x = 0;
                _local9.y = 0;
                _local10.x = 0;
                _local10.y = m_height;
                _local11.x = _local1.left;
                _local11.y = (m_height - _local1.bottom);
                _local12.x = _local1.left;
                _local12.y = _local1.top;
                drawBorderInRect(_local3.left, _local2.left, _local1.left, _local9, _local10, _local11, _local12, SIDE_LEFT);
            };
        }

    }
}//package reprise.ui.renderers 
